/*
 * SonarQube PDF Report
 * Copyright (C) 2010-2017 SonarSource SA
 * mailto:info AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.report.pdf.util;

import java.util.Properties;

/**
 * Example class demonstrating how to use ConfigUtil to read custom properties
 * for PDF generation configuration
 */
public class PDFConfigExample {

    /**
     * Get PDF configuration from custom properties file
     * 
     * @return Properties object with custom PDF configuration
     */
    public static Properties getCustomPDFConfig() {
        Properties config = new Properties();
        
        // Read all custom properties from custom-pdf.properties
        if (ConfigUtil.isConfigAvailable()) {
            // PDF generation settings
            config.setProperty("pdf.title", ConfigUtil.getProperty("pdf.title", "SonarQube PDF Report"));
            config.setProperty("pdf.author", ConfigUtil.getProperty("pdf.author", "SonarQube PDF Plugin"));
            config.setProperty("pdf.subject", ConfigUtil.getProperty("pdf.subject", "Code Quality Analysis Report"));
            config.setProperty("pdf.keywords", ConfigUtil.getProperty("pdf.keywords", "SonarQube,PDF,Report,Code Quality"));
            
            // Output settings
            config.setProperty("pdf.output.directory", ConfigUtil.getProperty("pdf.output.directory", "reports"));
            config.setProperty("pdf.filename.pattern", ConfigUtil.getProperty("pdf.filename.pattern", "sonar-report-{timestamp}.pdf"));
            config.setProperty("pdf.timestamp.format", ConfigUtil.getProperty("pdf.timestamp.format", "yyyyMMdd_HHmmss"));
            
            // Content settings
            config.setProperty("pdf.include.executive.summary", 
                String.valueOf(ConfigUtil.getBooleanProperty("pdf.include.executive.summary", true)));
            config.setProperty("pdf.include.team.workbook", 
                String.valueOf(ConfigUtil.getBooleanProperty("pdf.include.team.workbook", true)));
            config.setProperty("pdf.include.detailed.analysis", 
                String.valueOf(ConfigUtil.getBooleanProperty("pdf.include.detailed.analysis", true)));
            config.setProperty("pdf.max.issues.per.page", 
                String.valueOf(ConfigUtil.getIntProperty("pdf.max.issues.per.page", 50)));
            config.setProperty("pdf.show.code.snippets", 
                String.valueOf(ConfigUtil.getBooleanProperty("pdf.show.code.snippets", true)));
            
            // Formatting settings
            config.setProperty("pdf.font.family", ConfigUtil.getProperty("pdf.font.family", "msyh"));
            config.setProperty("pdf.font.size.normal", 
                String.valueOf(ConfigUtil.getIntProperty("pdf.font.size.normal", 10)));
            config.setProperty("pdf.font.size.title", 
                String.valueOf(ConfigUtil.getIntProperty("pdf.font.size.title", 16)));
            config.setProperty("pdf.font.size.heading", 
                String.valueOf(ConfigUtil.getIntProperty("pdf.font.size.heading", 12)));
            config.setProperty("pdf.margin.top", 
                String.valueOf(ConfigUtil.getIntProperty("pdf.margin.top", 50)));
            config.setProperty("pdf.margin.bottom", 
                String.valueOf(ConfigUtil.getIntProperty("pdf.margin.bottom", 50)));
            config.setProperty("pdf.margin.left", 
                String.valueOf(ConfigUtil.getIntProperty("pdf.margin.left", 50)));
            config.setProperty("pdf.margin.right", 
                String.valueOf(ConfigUtil.getIntProperty("pdf.margin.right", 50)));
            
            // Custom branding
            config.setProperty("company.logo", ConfigUtil.getProperty("company.logo", "custom-logo.png"));
            config.setProperty("company.name", ConfigUtil.getProperty("company.name", "Your Company Name"));
            config.setProperty("report.footer.text", ConfigUtil.getProperty("report.footer.text", "Generated by SonarQube PDF Plugin"));
        }
        
        return config;
    }

    /**
     * Example method showing how to use custom configuration in PDF generation
     */
    public static void demonstrateConfigUsage() {
        System.out.println("=== Custom PDF Configuration Demo ===");
        
        if (ConfigUtil.isConfigAvailable()) {
            System.out.println("Custom configuration file found and loaded successfully!");
            
            // Demonstrate reading various types of properties
            String title = ConfigUtil.getProperty("pdf.title");
            int maxIssues = ConfigUtil.getIntProperty("pdf.max.issues.per.page", 50);
            boolean includeSummary = ConfigUtil.getBooleanProperty("pdf.include.executive.summary", true);
            
            System.out.println("PDF Title: " + title);
            System.out.println("Max Issues Per Page: " + maxIssues);
            System.out.println("Include Executive Summary: " + includeSummary);
            System.out.println("Font Family: " + ConfigUtil.getProperty("pdf.font.family"));
            System.out.println("Company Name: " + ConfigUtil.getProperty("company.name"));
            
            // Get complete configuration as Properties object
            Properties config = getCustomPDFConfig();
            System.out.println("Total custom properties loaded: " + config.size());
            
        } else {
            System.out.println("Custom configuration file not available. Using default settings.");
        }
        
        System.out.println("=====================================");
    }
    
    /**
     * Main method for testing/demonstration
     */
    public static void main(String[] args) {
        demonstrateConfigUsage();
    }
}
